import axios from 'axios'
import addSignToHeader from './sign'
import { errorPrompt } from '@/plugins/error'

const instance = axios.create({
  baseURL: 'https://cycleif.cn:8080/api/v1/',
  // baseURL: 'http://localhost:8000/api/v1/',
  timeout: 5000
})

instance.interceptors.request.use(
  config => {
  
    return addSignToHeader(config)
  }, e => {
    return Promise.reject(e)
  }
)


instance.interceptors.response.use(
  res => {
    
    if (res.data.code == 200) {
      return res.data
    }
    
    errorPrompt(res.data.msg)
    return Promise.reject(new Error(res.data.msg))
  },
  e => {
    return Promise.reject(e)
  }
)

export default instance